package com.zoo.diannaopeijian.controller.component;

import com.zoo.diannaopeijian.common.filter.FilterUtil;
import com.zoo.diannaopeijian.controller.BaseController;
import com.zoo.diannaopeijian.domain.ComponentParameterDetail;
import com.zoo.diannaopeijian.service.ComponentParameterDetailService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 配件参数细节控制器
 */
@Controller
@RequestMapping("componentParameterDetail")
public class ComponentParameterDetailController extends BaseController {
    @Resource
    private ComponentParameterDetailService componentParameterDetailService;

    @GetMapping("/")
    public ResponseEntity<List<ComponentParameterDetail>> componentParameterDetailGet(ComponentParameterDetail componentParameterDetail) {
        return ResponseEntity.ok(componentParameterDetailService.getComponentParameterDetail(componentParameterDetail));
    }

    @GetMapping("/filter")
    public ResponseEntity<List> filterComponentParameterDetailGet(ComponentParameterDetail componentParameterDetail) {
        return ResponseEntity.ok(FilterUtil.getFilterData(componentParameterDetailService.getComponentParameterDetail(componentParameterDetail), "compParamDetId", "compParamDetName"));
    }

    @PostMapping("/")
    public ResponseEntity<String> componentParameterDetailPost(ComponentParameterDetail componentParameterDetail) {
        return ResponseEntity.ok(componentParameterDetailService.addComponentParameterDetail(componentParameterDetail) ? success : fail);
    }

    @DeleteMapping("/{componentParameterDetailId}")
    public ResponseEntity<String> componentParameterDetailDelete(@PathVariable Integer componentParameterDetailId) {
        return ResponseEntity.ok(componentParameterDetailService.deleteComponentParameterDetailById(componentParameterDetailId) ? success : fail);
    }

    @PutMapping("/")
    public ResponseEntity<String> componentParameterDetailPut(ComponentParameterDetail componentParameterDetail) {
        return ResponseEntity.ok(componentParameterDetailService.updateComponentParameterDetail(componentParameterDetail) ? success : fail);
    }
}
